
var _datatableOpts ={
	 "iDisplayLength" : 10,
	 "bSort":false,
	 "bLengthChange": false,
	 "bFilter": false,
	 "bProcessing": true,
	 "bServerSide": true,
	 ajax: {
        url:"../script/objects.txt",
        dataSrc:'object'
     }, 
	 "fnServerParams": function (aoData,oSettings) {
		 //aoData.push({name: "start_date", value: $scope.AuditBehavior.start_date});
		 //aoData.push({name: "end_date", value: $scope.AuditBehavior.end_date});
	 }, 
	 "sPaginationType": "full_numbers",
	 "oLanguage": {
	 "oPaginate": {
		 "sFirst": "首页",
		 "sLast": "尾页",
		 "sNext": "下一页",
		 "sPrevious": "上一页"
	 },
	 "sProcessing": "正在获取数据，请稍等",
	 "sLengthMenu": "每页显示 _MENU_ 数据",
	 "sZeroRecords": "未检索到符合条件的数据",
	 "sInfo": "显示 第_START_ 到 _END_ 条数据 共 _TOTAL_ 数据",
	 "sInfoEmpty": "未检索到符合条件的数据",
	 "sInfoFiltered": "(共 _MAX_ 条数据)"
	 } 
};
var _commDir = angular.module('_commDir',[]);

//表格模版
_commDir.directive('tabletpl',function($timeout) {
	return {
			replace:true,
            restrict: 'A',
            link:function(scope, element, attrs) {
                // apply DataTable options, use defaults if none specified by user
                console.log(attrs)
                var options = {};
                options = _datatableOpts;
                //options.sAjaxSource = attrs.api;
                //options.ajax = attrs.api;
                // Tell the dataTables plugin what columns to use
                // We can either derive them from the dom, or use setup from the controller           
                var explicitColumns = [];
                element.find('th').each(function(index, elem) {
                    explicitColumns.push($(elem).text());
                });
                if (explicitColumns.length > 0) {
                    options["aoColumns"] = explicitColumns;
                } else if (attrs.aoColumns) {
                    options["aoColumns"] = scope.$eval(attrs.aoColumns);
                }
 				
                // aoColumnDefs is dataTables way of providing fine control over column config
                if (attrs.columnscfg) {
                    //options["aoColumnDefs"] = scope.$eval(attrs.columnscfg);
                    options["columns"] = scope.$eval(attrs.columnscfg);
                }
                options["fnCreatedRow"] = function(nRow, aData, iDataIndex) {
                    return nRow = $compile(nRow)(scope);
                };
                // apply the plugin
                scope.$watch(attrs.refresh, function() {
                    /*if(typeof(dataTable) != undefined) {
                    	dataTable.fnDraw();
                    }*/
                });
                var dataTable = element.dataTable(scope.$eval({options}));
                console.log(dataTable)
            }
        }
});

_commDir.directive('test-test',function() {
	return {
		replace:true,
		template:'<div>哈哈啊哈</div>'
	}
});
_commDir.directive('formlabeltext',function() {
    return {
        replace:true,
        restrict:'E',
        template:function (element,attrs) {
            return '<div class="form-group"><label class="control-label col-sm-1">'+attrs.label+'</label><div class="col-sm-4"><input type="text" class="form-control" placeholder="'+attrs.placeholder+'"/></div></div>';
        }
    }
});
_commDir.directive('formlabel',function() {
    return {
        replace:true,
        restrict:'E',
        template:function (element,attrs) {
            return '<div class="form-group"><label class="control-label col-sm-1">'+attrs.label+'</label></div>';
        }
    }
});